
/* -*- C++ -*- */

//=============================================================================
/*
* @author Feloweria <380374483@qq.com>
* Copyright (C) Feloweria
*
* $ID 2014-07-03 15:04:05 AM
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* @version 1.0
*/
//=============================================================================

FELOWRIA_BEGINE

inline DataInputStream::DataInputStream(char *data,char *data_end)
	:data(data),data_end(data_end)
{

}

inline DataInputStream::~DataInputStream() 
{

}

inline int32 DataInputStream::Writable() const
{
	return data_end - data;
}

inline void DataInputStream::Writable(char *&wdPtr, int32 &size)
{
	wdPtr = data;
	size = data_end - data;
}

inline bool DataInputStream::Write(const char *bytes, uint32 size)
{
	if(!WritePeek(bytes,size))
		return false;

	data + = size;
	return true;
}

inline bool DataInputStream::WritePeek(const char *bytes, uint32 size)
{
	if(!bytes || !size || data + size > data_end)
		return false;

	memcpy(data, bytes ,size);


	return true;
}

inline bool DataInputStream::WriteSkip(uint32 size)
{
	if(data + size > data_end)
		return false;
	
	data += size;

	return true;
}

inline int32 DataInputStream::WriteSize() const
{
	return Writable();
}

FELOWRIA_END